/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.kimstore.gui.sales;

import com.kimstore.bean.Item;
import com.kimstore.bean.ItemStatus;
import com.kimstore.bean.Staff;
import com.kimstore.factory.DaoFactory;
import java.util.Date;

/**
 *
 * @author Administrator
 */
public class ViewUpdateItemController {
    
    private ViewUpdateOrderController parentController;
    private ViewUpdateItemWindow window;
    
    private Item item = null;
    
    public ViewUpdateItemController(ViewUpdateOrderController parentController, String sku){
        this.parentController = parentController;
        
        item = DaoFactory.getInstance().getItemDao().findBySerial(sku);
    }
    
    public void displayWindow(){
        window = new ViewUpdateItemWindow(this);
        window.populateWindow(item, DaoFactory.getInstance().getStaffDao().findAll());
        window.showWindow();
    }
    
    public void fromWindow(){
        
    }
    public void addItemHistory(String status, String staffName, Date dateX) {
        Staff staff = DaoFactory.getInstance().getStaffDao().findByName(staffName);
        ItemStatus itemStatus = new ItemStatus(status, dateX, staff);
        
        item.addHistory(itemStatus);
        DaoFactory.getInstance().getItemDao().saveOrUpdate(item);
        window.populateItemHistoryTable(item);
    }

    void removeHistory(int row) {
        item.getHistory().remove(item.getHistory().get(row));
        window.populateItemHistoryTable(item);
        DaoFactory.getInstance().getItemDao().saveOrUpdate(item);

        parentController.refreshDeliveryHistoryStatus();
    }
    
}
